// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   LoggerServiceImpl.java

package cn.com.pusai.base.logger.service.impl;

//import cn.com.pusai.base.login.model.LoginObject;
import cn.com.pusai.common.service.impl.BaseServiceImpl;
import cn.com.pusai.common.util.*;
import cn.com.pusai.core.exception.ServiceException;
import cn.com.pusai.base.logger.dao.LoggerDAO;
import cn.com.pusai.base.logger.service.LoggerService;
import cn.com.pusai.base.logger.model.SysLog;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

public class LoggerServiceImpl extends BaseServiceImpl
	implements LoggerService
{

	public static final String DEFAULT_MODULE_CODE = "default";
	public static final String OPERATE_TYPE_LOGIN = "login";
	public static final String OPERATE_TYPE_LOGOUT = "logout";
	public static final String OPERATE_TYPE_ADD = "add";
	public static final String OPERATE_TYPE_MODIFY = "edit";
	public static final String OPERATE_TYPE_DELETE = "del";
	public static final String OPERATE_TYPE_VIEW = "view";
	public static final String OPERATE_TYPE_IMPORT = "import";
	public static final String OPERATE_TYPE_EXPORT = "export";
	public static final String OPERATE_TYPE_SUBMITAUDIT = "submitAudit";
	public static final String OPERATE_TYPE_AUDIT = "audit";
	public static final Short RESULT_SUCCESS = Short.valueOf((short)1);
	public static final Short RESULT_FAILED = Short.valueOf((short)0);
	private LoggerDAO loggerDAO;

	public LoggerServiceImpl()
	{
	}

	public void setLoggerDAO(LoggerDAO loggerDAO)
	{
		super.setDAO(loggerDAO);
		this.loggerDAO = loggerDAO;
	}

	private SysLog getLogger(String moduleCode)
		throws ServiceException
	{
//		LoginObject loginObject = SystemUtil.getLoginObject();
		SysLog logger = new SysLog();
//		logger.setPersonAccount(loginObject.getLogin());
//		logger.setPersonName(loginObject.getPersonName());
//		logger.setClientIp(loginObject.getIp());
//		logger.setModuleCode(moduleCode);
//		logger.setOperateTime(new Date());
		return logger;
	}

	private SysLog getLoggerNoModule(String personAccount, String personName)
		throws ServiceException
	{
		SysLog logger = new SysLog();
		logger.setPersonAccount(personAccount);
		logger.setPersonName(personName);
		logger.setClientIp(ServletUtil.getCurrentHttpRequest().getRemoteAddr());
		logger.setModuleCode("default");
		logger.setOperateTime(new Date());
		return logger;
	}

	public void logViewFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("view");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logViewSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("view");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logAddSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("add");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logAddFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("add");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logModifySuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("edit");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logModifyFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("edit");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logDeleteSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("del");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logDeleteFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("del");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logAuditSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("audit");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logAuditFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("audit");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logExportSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("export");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logExportFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("export");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logImportSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("import");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logImportFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("import");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logLogoutFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger("default");
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("logout");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logLogoutSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger("default");
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("logout");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logLoginSuccess(String username, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLoggerNoModule(username, "");
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("login");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logLoginFailed(String username, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLoggerNoModule(username, "");
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("login");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logSubmitAuditSuccess(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("submitAudit");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logSubmitAuditFailed(String moduleCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("submitAudit");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logModPasswordSuccess(String username, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLoggerNoModule(username, "");
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("edit");
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logModPasswordFailed(String username, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLoggerNoModule(username, "");
		logger.setOperateDesc(operateDesc);
		logger.setOperateType("edit");
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public void logCustomOperateSuccess(String moduleCode, String operateCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType(operateCode);
		logger.setResult(RESULT_SUCCESS);
		loggerDAO.create(logger);
	}

	public void logCustomOperateFailed(String moduleCode, String operateCode, String operateDesc)
		throws ServiceException
	{
		SysLog logger = getLogger(moduleCode);
		logger.setOperateDesc(operateDesc);
		logger.setOperateType(operateCode);
		logger.setResult(RESULT_FAILED);
		loggerDAO.create(logger);
	}

	public List findLogger()
		throws ServiceException
	{
		SearchMap searchMap = new SearchMap();
		return loggerDAO.findObjects(searchMap);
	}

}
